package com.cuotigou.controller;

import com.cuotigou.service.LabelService;
import com.cuotigou.util.ObjectResult;
import com.cuotigou.util.StringUtil;
import com.cuotigou.util.XMLBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2018/11/11.
 */
@Controller
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    /**
     * 错题标签
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/wrongTopic")
    @ResponseBody
    public ObjectResult wrongTopic(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }

        return labelService.wrongTopicLabel(xmlBean);
    }

    /**
     * 添加标签
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult add(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }
        if(StringUtil.isEmpty(xmlBean.getTitle())){
            return ObjectResult.build("0","标签名不能为空");
        }

        return labelService.addLabel(xmlBean);
    }

    /**
     * 题库标签
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/questionBank", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult questionBank(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }

        return labelService.questionBankLabel(xmlBean);
    }

    /**
     * 悬赏标签
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/offerReward", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult offerReward(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }

        return labelService.offerRewardLabel(xmlBean);
    }

    /**
     * 错题筛选标签
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/screenLabel", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult screenLabel(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }

        return labelService.wrongTopicScreenLabel(xmlBean);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public ObjectResult update(XMLBean xmlBean) {
        if (StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }

        return labelService.labelUpdate(xmlBean);
    }
}
